function init() {
    document.title = chrome.i18n.getMessage("extOptionPageTitle");
    var siteOptionLabel = document.getElementById('labelSite');
    siteOptionLabel.innerHTML = chrome.i18n.getMessage("labelSiteOption");
    var quitButton = document.getElementById('quit');
    quitButton.innerHTML = chrome.i18n.getMessage("quitOptionButton");
}

function saveOptions() {
    var siteInput = document.getElementById('site');
    chrome.storage.sync.set({
	site : siteInput.checked
    });

    var status = document.getElementById("status");
    status.innerHTML = chrome.i18n.getMessage("saveOptionMsg");
    status.style.opacity = "100";
    setTimeout(function() {
	status.style.opacity = "0";
	status.innerHTML = "";
    }, 750);
}

function restoreOptions() {
    chrome.storage.sync.get('site', function(data) {
	var siteInput = document.getElementById('site');

	if (data.site) {
	    siteInput.checked = true;
	} else {
	    siteInput.checked = false;
	}
    });
}

function closeTab(tab) {
    chrome.tabs.getCurrent(function(tab) {
	chrome.tabs.remove(tab.id);
    });
}

document.addEventListener('DOMContentLoaded', init);
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('site').addEventListener('click', saveOptions);
document.getElementById('quit').addEventListener('click', closeTab);
